<?php
if( ! defined('BASEPATH')) exit('No direct script access allowed');

class aboutme extends CI_Controller
{


	function __construct()
	{
		parent::__construct();
		// check if user logged in
		if(!$this->ion_auth->logged_in()){
			redirect('auth/login');
		}
		$this->load->library('form_validation');
		$this->load->model('user/about_model');
	}
	
	function addabout($id=null)
	{
		if(isset($id))
		{
			$user= $id;
		}else
		{
			$user=$this->session->userdata('user_id');		
		}
		$data['userid'] = $user;
		$data['hobbies'] = $this->about_model->hobbies_getall();
		//$data['userid'] = $id;
		$meta['page_title'] = "Create About Me";
		$this->load->view('common/header',$meta);
		$this->load->view('user/add-aboutme',$data);
		$this->load->view('common/footer');
				
	}
	
	function getallaboutlist()
	{
		
		//$this->form_validation->set_rules('efficiencyname[]', 'efficiencyname', 'required');
		$this->form_validation->set_rules('schoolname', 'Schoolname', 'required');
		//$this->form_validation->set_rules('hobbies', 'Hobbies', 'required');
		if ($this->form_validation->run() == TRUE)
		{		
			$users = $this->input->post('users');	
			$schoolname = $this->input->post('schoolname');
			$degree = $this->input->post('degree');
			$started = $this->input->post('started');
			$ended = $this->input->post('ended');
			
			$combine_education = array();
			for($x=0;$x<count($schoolname);$x++)
			{
				$combine_education[$x]['user_id'] = $users;
				$combine_education[$x]['institute'] = $schoolname[$x];
				$combine_education[$x]['degree'] = $degree[$x];
				$combine_education[$x]['started'] = $started[$x];
				$combine_education[$x]['ended'] = $ended[$x];
			}
							
		$this->about_model->education_insert($combine_education);
			
			
			$language = $this->input->post('language');
			if(!empty($language))
			{
			$this->about_model->language_insert($language,$users);
			}	
		
	
			$phone = $this->input->post('phone');
			if(!empty($phone))
			{
				$this->about_model->phone_update($phone,$users);
			}
			
			$username = $this->input->post('user');
		
			if(!empty($username))
			{
			$this->about_model->user_update($username,$users);
			}
			$street=$this->input->post('street');
		
				$insert = array('user_id'=>$this->input->post('users'),
						'street'=>$this->input->post('street'),
						'zipcode'=>$this->input->post('zipcode'),
						'city'=>$this->input->post('city'),
						'state'=>$this->input->post('state'),
						'country'=>$this->input->post('country'),);
				if(!empty($street))
			{						
				$this->about_model->address_insert($insert);
			}
			
			
			$hobbiesid = $this->input->post('hobbies');
			if(!empty($hobbiesid))
			{
				
			$combine_hobbies = array();
			
			for($x=0;$x<count($hobbiesid);$x++)
			{
				$combine_hobbies[$x]['user_id'] = $users;
				$combine_hobbies[$x]['hobbies_id'] = $hobbiesid[$x];
			}
	
								
			$this->about_model->user_hobbies_insert($combine_hobbies);
			}
			redirect('user/aboutme/viewabout/');
	
	}		
	}
	
	
	function viewabout($id=null)
	{
		//$data['userid'] = $id;
		if(isset($id))
		{
			$user= $id;
		}else
		{
			$user=$this->session->userdata('user_id');		
		}
		$data['userid'] = $user;
		
		$data['designationbyid'] = $this->about_model->designationbyid($user);
		$data['userdetails'] = $this->about_model->userdetails($user);
		$data['address'] = $this->about_model->get_address_by_userid($user);
		$data['education'] = $this->about_model->get_education_by_userid($user);
		$data['language'] = $this->about_model->get_language_by_userid($user);
		$data['skillsimage'] = $this->about_model->skillsimage($user);
		$data['skillschart'] = $this->about_model->skillschart($user);
		$data['efficiencychart'] = $this->about_model->efficiencychart($user);
		$data['hobbyimage'] = $this->about_model->hobbyimage($user);
		$data['coffeebyid'] = $this->about_model->coffeebyid($user);
		$data['efficiencyfields'] = $this->about_model->efficiencyfields($user);
		$data['toolschart'] = $this->about_model->toolschart($user);
		$data['user'] = $this->about_model->get_user_details($this->session->userdata('user_id'));
		
		$meta['page_title'] = "View About Me";
		$this->load->view('common/header',$meta);
		$this->load->view('user/view-about',$data);
		$this->load->view('common/footer');
		//echo $id;

	}
		
}
